package io.gitee.yth.design.pattern.test.core.pattern.behavioral.state;

/**
 * 上下文环境
 * 1. 定义客户感兴趣的接口
 * 2. 维护一个ConcreteState实例，这个实例定义当前状态
 *
 * @author yth
 * @since 2023-05-03-0:16
 */
public class TCPConnection {

    /**
     * 当前状态实例
     */
    private TCPState tcpState;

    public TCPConnection() {
        this.tcpState = TCPClosed.getInstance();    // 初始状态
    }

    void changeState(AbstractTCPState tcpState) {
        this.tcpState = tcpState;
    }

    public void activeOpen() {
        tcpState.activeOpen(this);
    }

    public void passiveOpen() {
        tcpState.passiveOpen(this);
    }

    public void close() {
        tcpState.close(this);
    }

    public void send() {
        tcpState.send(this);
    }

    public void acknowledge() {
        tcpState.acknowledge(this);
    }

    public void synchronize() {
        tcpState.synchronize(this);
    }

    public void processOctet(TCPOctetStream tcpOctetStream) {
        System.out.println("processOctet ...");
    }
}
